const Controller = require('egg').Controller;

class CompanyController extends Controller {


    async info () {

        const { ctx } = this;

        const company_code = ctx.query.company_code;
        const r = await ctx.service.company.info(company_code);
        //console.log(r);
        this.ctx.helper.success(r);
    }


    async toRedis () {
        const { ctx } = this;
        const r = await ctx.service.company.toRedis();
        //console.log(r);
        this.ctx.helper.success(r);
    }


    async account () {
        const result = await this.ctx.service.company.account();
        this.ctx.helper.success(result);
    }

    //微信扫码完之后往redis里存一个成功值
    async setRegisterSuccess(){

        const { ctx, app } = this;

        const company_code = ctx.request.body.company_code;

        const user = ctx._user;

        //ctx.logger.info(user);

        await app.redis.get('tmp').hset('dlq_register_tmp', company_code, JSON.stringify(user));

        ctx.helper.success('1');

    }


    //微信扫码完之后往redis里存一个成功值
    async getRegisterState(){

        const { ctx, app } = this;

        const company_code = ctx.request.body.company_code;

        const result = await app.redis.get('tmp').hget('dlq_register_tmp', company_code);

        if(result == null){
            ctx.helper.error('error');
        }else{
            ctx.helper.success(result);
        }

    }

    //更新微信配置
    async updateWeixinConfig () {

        const { ctx, app } = this;

        const { wxid, appid, appsecret, filename, filecontent } = ctx.request.body;

        const result = await ctx.service.company.updateAccount({
            wxid, appid, appsecret, filename, filecontent
        });

        ctx.helper.success(result);
        
    }

    
}
module.exports = CompanyController;